//
//  YouBeautyBaseViewController.m
//  YouBeauty
//
//  Created by Kelly xu on 2019/4/4.
//  Copyright © 2019 changrenTech. All rights reserved.
//

#import "YouBeautyBaseViewController.h"
@implementation YouBeautyBaseViewController
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = Color(@"F9F9F9");
    [self setNavTopLayout];
    [self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
    //去掉透明后导航栏下边的黑边
    [self.navigationController.navigationBar setShadowImage:[[UIImage alloc] init]];
    [self setNavTitleColor:[UIColor whiteColor]];
    if ([self.rt_navigationController.rt_viewControllers count]>1) {
        [self setNavLeftBtnForImage:[UIImage imageNamed:@"icon_fanhui"]];
    }
    
}
- (void)viewWillAppear:(BOOL)animated{
    if ([self.rt_navigationController.rt_viewControllers count]>1) {
        [self.rdv_tabBarController setTabBarHidden:YES animated:YES];
    }else{
        [self.rdv_tabBarController setTabBarHidden:NO animated:YES];
    }
}
-(void)setNavBarHidden{
    self.navigationController.navigationBarHidden = YES;
}

-(void)setNavBottomLayout{
    self.edgesForExtendedLayout=UIRectEdgeBottom;
}
-(void)setNavTopLayout{
    self.edgesForExtendedLayout = UIRectEdgeTop;
    self.extendedLayoutIncludesOpaqueBars = NO;
}
-(void)setNavLeftBtn:(NSString*)text color:(UIColor*)color{
    UIBarButtonItem *fix = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
    fix.width = 15;
    
    kWeakSelf;
    SMBButton *leftBtn = [[SMBButton alloc]initWithFrame:CGRectMake(0, 0, 44, 44) title:text pressed:^(UIButton *button) {
        kStrongSelf;
        [strongSelf leftbuttonPressed:button];
    }];
    [leftBtn.titleLabel setFont:font14];
    if (!color) {
        [leftBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    }else{
        [leftBtn setTitleColor:color forState:UIControlStateNormal];
    }
    UIBarButtonItem *buttonItem = [[UIBarButtonItem alloc]initWithCustomView:leftBtn];
    
    self.navigationItem.leftBarButtonItems = @[fix,buttonItem];
}
-(void)setNavRightBtn:(NSString*)text color:(UIColor*)color{
    UIBarButtonItem *fix = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
    fix.width = 15;
    
    kWeakSelf;
    SMBButton *rightBtn = [[SMBButton alloc]initWithFrame:CGRectMake(0, 0, 44, 44) title:text pressed:^(UIButton *button) {
        kStrongSelf;
        [strongSelf rightbuttonPressed:button];
    }];
    [rightBtn.titleLabel setFont:font14];
    if (!color) {
         [rightBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    }else{
         [rightBtn setTitleColor:color forState:UIControlStateNormal];
    }
    UIBarButtonItem *buttonItem = [[UIBarButtonItem alloc]initWithCustomView:rightBtn];
    
    self.navigationItem.rightBarButtonItems = @[buttonItem,fix];
}

-(void)setNavTitleColor:(UIColor*)color{
    [self.navigationController.navigationBar setTitleTextAttributes:@{
                                                                      NSForegroundColorAttributeName:color,
                                                                      NSFontAttributeName: [UIFont systemFontOfSize:18],}];
}

-(void)setNavColor:(UIColor*)color{
    [self.navigationController.navigationBar setShadowImage:[UIImage new]];
    self.navigationController.navigationBar.barTintColor = color;
    self.navigationController.navigationBar.barStyle = UIBarStyleDefault;
    self.navigationController.navigationBar.translucent = NO;
}
-(void)setNavTitleColor:(UIColor*)color title:(NSString*)title{
    self.navigationItem.title = title;
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont fontWithName:@"PingFangSC-Semibold" size:16],NSForegroundColorAttributeName:color}];
}
-(void)setNavBottomLineColor:(UIColor*)color{
//    UIImage *colorImg = [UIImage imageWithColor:color];
//    [self.navigationController.navigationBar setShadowImage:colorImg];
}

-(void)setNavLeftBtnForImage:(UIImage*)image{
    UIBarButtonItem *fix = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
    fix.width = -15;
    kWeakSelf;
    SMBButton *button = [[SMBButton alloc]initWithFrame:CGRectMake(0, 0, 44, 44) title:@"" pressed:^(UIButton *button) {
        kStrongSelf;
        [strongSelf leftbuttonPressed:button];
    }];
    [button setImage:image forState:UIControlStateNormal];
    UIBarButtonItem *buttonItem = [[UIBarButtonItem alloc]initWithCustomView:button];
    self.navigationItem.leftBarButtonItems = @[fix,buttonItem];
}
-(void)setNavRightBtnForImage:(UIImage*)image rightBtn2ForImage:(UIImage*)image2{
    UIBarButtonItem *fix = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
    fix.width = 15;
    kWeakSelf;
    SMBButton *button = [[SMBButton alloc]initWithFrame:CGRectMake(0, 0, 44, 44) title:@"" pressed:^(UIButton *button) {
        kStrongSelf;
        [strongSelf rightbuttonPressed:button];
    }];
    [button setImage:image forState:UIControlStateNormal];
    UIBarButtonItem *buttonItem = [[UIBarButtonItem alloc]initWithCustomView:button];
    SMBButton *button2 = [[SMBButton alloc]initWithFrame:CGRectMake(0, 0, 44, 44) title:@"" pressed:^(UIButton *button) {
        kStrongSelf;
        [strongSelf rightbuttonPressed2:button];
    }];
    [button2 setImage:image2 forState:UIControlStateNormal];
    UIBarButtonItem *buttonItem2 = [[UIBarButtonItem alloc]initWithCustomView:button2];
    self.navigationItem.rightBarButtonItems = @[buttonItem2,buttonItem,fix];
}
-(void)setNavRightBtnForImage:(UIImage*)image{
    UIBarButtonItem *fix = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
    fix.width = 15;
    kWeakSelf;
    SMBButton *button = [[SMBButton alloc]initWithFrame:CGRectMake(0, 0, 44, 44) title:@"" pressed:^(UIButton *button) {
        kStrongSelf;
        [strongSelf rightbuttonPressed:button];
    }];
    [button setImage:image forState:UIControlStateNormal];
    UIBarButtonItem *buttonItem = [[UIBarButtonItem alloc]initWithCustomView:button];
    self.navigationItem.rightBarButtonItems = @[buttonItem,fix];
}
-(void)setNavRightBtnForBackImage:(UIImage*)image{
    //    UIBarButtonItem *fix = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
    //    fix.width = 15;
    //    kWeakSelf;
    //    SMBButton *button = [[SMBButton alloc]initWithFrame:CGRectMake(0, 0, 44, 44) title:@"" pressed:^(UIButton *button) {
    //        kStrongSelf;
    //        [strongSelf rightbuttonPressed:button];
    //    }];
    //    [button setBackgroundColor:[UIColor blackColor]];
    //    //    [button.imageView setContentMode:UIViewContentModeScasleAspectFill];
    //    [button setImage:image forState:UIControlStateNormal];
    //    [button setImage:image forState:UIControlStateHighlighted];
    //
    //    UIView *contentView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 44, 44)];
    //    [contentView addSubview:button];
    //    UIBarButtonItem *buttonItem = [[UIBarButtonItem alloc]initWithCustomView:contentView];
    //    self.navigationItem.rightBarButtonItem = buttonItem;
}

-(void)setNavRightBtnForImage:(UIImage*)image andTitle:(NSString *)title {
    UIBarButtonItem *fix = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
    fix.width = -8;
    kWeakSelf;
    SMBButton *button = [[SMBButton alloc]initWithFrame:CGRectMake(DEVICE_WIDTH-54, 4, 44, 36) title:title pressed:^(UIButton *button) {
        kStrongSelf;
        [strongSelf rightbuttonPressed:button];
    }];
    [button setTitleColor:Color(@"FE3451") forState:UIControlStateNormal];
    button.titleLabel.font = [UIFont systemFontOfSize:14];
    [button setImage:image forState:UIControlStateNormal];
    //UIBarButtonItem *buttonItem = [[UIBarButtonItem alloc]initWithCustomView:button];
    //self.navigationItem.rightBarButtonItems = @[fix,buttonItem];
    [self.navigationController.navigationBar addSubview:button];
}

-(void)leftbuttonPressed:(id)sender{
    [self.rt_navigationController popViewControllerAnimated:YES];
}

-(void)rightbuttonPressed:(id)sender{
    
}
-(void)rightbuttonPressed2:(id)sender{
    
}
#pragma mark - keyboard handle
-(void)dissmissKeyBoard{
    [[[UIApplication sharedApplication] keyWindow] endEditing:YES];//关闭键盘
}
/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */
@end
